package com.jinxin.platform.cdacscontrolmgr.task;

import com.jinxin.platform.cdacscontrolmgr.bean.CdacscontrolmgrRegistInfo;
import com.jinxin.platform.cdacscontrolmgr.common.Constant;
import com.jinxin.platform.cdacscontrolmgr.mapper.CdacscontrolmgrRegistInfoMapper;
import com.jinxin.platform.cdacscontrolmgr.rpc.CdacscontrolmgrRpc;
import com.jinxin.platform.cdacscontrolmgr.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Description: bccah
 * Created by 34759 on 2019/8/16 15:57
 */
@EnableScheduling
@Configuration
@Component
public class AcsRegistInfoTask {
    @Autowired
    private CdacscontrolmgrRegistInfoMapper registInfoMapper;
    @Autowired
    private CdacscontrolmgrRpc cdacscontrolmgrRpc;
    private ScheduledExecutorService executorService =
            Executors.newSingleThreadScheduledExecutor();

    /**
     * 每天12点，删除登记表中前一天的人脸头像
     */
    @Scheduled(cron = "0 0 0 * * ? ")
    public void acsRegistFaceDelete(){
        HashMap param = new HashMap();
        param.put("visitDate", DateUtil.getLastDay());
        List<CdacscontrolmgrRegistInfo> list = registInfoMapper.list(param);
        for(CdacscontrolmgrRegistInfo registInfo : list){
            executorService.schedule(() -> {
                cdacscontrolmgrRpc.deletePortraitData(registInfo.getId(),registInfo.getProjectId());
            }, Constant.SLEEP_TIME_500, TimeUnit.MILLISECONDS);
        }
    }

}
